package com.snowyee.yudada.scoring;

import com.snowyee.yudada.common.ErrorCode;
import com.snowyee.yudada.exception.BusinessException;
import com.snowyee.yudada.model.entity.App;
import com.snowyee.yudada.model.entity.UserAnswer;
import com.snowyee.yudada.model.enums.AppTypeEnum;
import com.snowyee.yudada.model.enums.ScoringStrategyEnum;
import com.snowyee.yudada.scoring.impl.CustomScoreScoringStrategyImpl;
import com.snowyee.yudada.scoring.impl.CustomTestScoringStrategyImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
@Deprecated
public class ScoringStrategyContext {

    @Resource
    private CustomScoreScoringStrategyImpl customScoreScoringStrategy;

    @Resource
    private CustomTestScoringStrategyImpl customTestScoringStrategy;

    /**
     * 根据策略类型获取策略对象
     */

    public UserAnswer doScore(List<String> choiceList, App app) throws Exception {
        AppTypeEnum appTypeEnum = AppTypeEnum.getEnumByValue(app.getAppType());
        ScoringStrategyEnum scoringStrategyEnum = ScoringStrategyEnum.getEnumByValue(app.getScoringStrategy());

        if (appTypeEnum == null || scoringStrategyEnum == null) {
            throw new BusinessException(ErrorCode.SYSTEM_ERROR,"应用配置有误，未找到匹配的策略");
        }

        // 根据不同的应用类型和评分策略，选择对应的策略执行
        switch (appTypeEnum) {

            case SCORE:
                switch (scoringStrategyEnum) {
                    case CUSTOM:
                        return customScoreScoringStrategy.doScore(choiceList, app);
                    case AI:
                        break;
                }


            case TEST:
                switch (scoringStrategyEnum) {
                    case CUSTOM:
                        return customTestScoringStrategy.doScore(choiceList, app);
                    case AI:
                        break;
                }

                break;
        }

        throw new BusinessException(ErrorCode.SYSTEM_ERROR,"应用配置有误，未找到匹配的策略");
    }
}
